package rule18;

import java.util.Collection;
import java.util.Iterator;
import java.util.Set;

/**
 * @author ChangLiang
 * @date 2020/3/17
 */
public class HashSetCounterV2 implements Set {

    private Set set;

    private int count = 0;

    public HashSetCounterV2(Set set) {
        this.set = set;
    }

    @Override
    public boolean add(Object o) {
        count++;
        return set.add(o);
    }

    @Override
    public boolean addAll(Collection c) {
        count += c.size();
        return set.addAll(c);
    }

    public int getCount() {
        return count;
    }

    @Override
    public int size() {
        return set.size();
    }

    @Override
    public boolean isEmpty() {
        return set.isEmpty();
    }

    @Override
    public boolean contains(Object o) {
        return set.contains(o);
    }

    @Override
    public Iterator iterator() {
        return set.iterator();
    }

    @Override
    public Object[] toArray() {
        return set.toArray();
    }

    @Override
    public boolean remove(Object o) {
        return set.remove(o);
    }

    @Override
    public void clear() {
        set.clear();
    }

    @Override
    public boolean removeAll(Collection c) {
        return set.removeAll(c);
    }

    @Override
    public boolean retainAll(Collection c) {
        return set.retainAll(c);
    }

    @Override
    public boolean containsAll(Collection c) {
        return set.containsAll(c);
    }

    @Override
    public Object[] toArray(Object[] a) {
        return set.toArray(a);
    }
}
